// index.js
import { getBannerList ,getGoodsCate ,getGoodsList} from "../../utils/api"
// 获取应用实例
const app = getApp()

Page({
  data: {
    bannerList:[],
    goodsCategory:[],
    couunt:{
      page:1,
      pageSize:50
    },
    goodsList:[]
  },
  onLoad() {
    this.getBanner()
    this.getGoods()
    this.getGoodsArr()
    // if (wx.getUserProfile) {
    //   this.setData({
    //     canIUseGetUserProfile: true
    //   })
    // }
  },
  getBanner() {

    getBannerList().then(res => {
      // console.log(res);
      let banner = res.data.filter(item => {
        return item.type == "index"
      })
      this.setData({
        bannerList: banner
      })
    })
  },
  getGoods(){
    getGoodsCate().then(res=>{
      // console.log(res);
      this.data.goodsCategory = res.data
      
      this.setData({
        goodsCategory: this.data.goodsCategory
      })
    })
  },
  getGoodsArr(){
    getGoodsList().then(res=>{
      console.log(res);
      this.setData({
        goodsList:res.data.result
      })
    })
  },
  goGoodsDetail(e){
    console.log(e.currentTarget.dataset.detail.id);
    const id = e.currentTarget.dataset.detail.id
    wx.navigateTo({
      url: `../goodsDetail/index?id=${id}`
    })
  },
  goKind(e){
    const id = e.currentTarget.dataset.detail.id
    // console.log(id);
    wx.reLaunch({
      url: `../kind/index?id=${id}`
    })
  }
})
